<template>
	<div>
		<van-nav-bar>
			<template #left>
				&nbsp;&nbsp;
				<van-icon size="0.8rem" color="black" name="wap-nav" />
			</template>

			<template #title>
				<router-link to="/search">搜索</router-link>
			</template>

			<template #right>
				<!-- 登录未登录 -->
				<router-link v-if="show" to="/login">登录 </router-link>
				<!-- <router-link v-if="!show" to="/uercenter">头像 </router-link> -->
				<router-link v-if="!show" to="/uercenter"><van-image class="himg" round :src="url" @click="show = true" /></router-link>
				<!-- 测试跳转 -->
				<!-- <router-link to="/musicdetail">&nbsp;音乐</router-link> -->
			</template>
		</van-nav-bar>
	</div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
// import { RequestUserStatus,RequestUserStatus2} from "@/api/user"
import { Notify } from 'vant'

// 获取持久化存储数据 (测试)
import { useuidStore } from '@/stores/user'
const userstore = useuidStore()
let fn1 = ()=>{
  console.log("uid>>>",userstore.user.uid);
}
fn1()
let fn2 = ()=>{
//   userstore.saveUser()
}

// 头像
let url = ref("https://www.mp3pc.com/uploads/fdabf4b09939c4bb9704dd466c99375d.jpg")
// 头像开关
let show = ref(true)


let useUserStatus = async () => {
	console.log(1);
	
	if(userstore.user.uid){
		show.value = false
		Notify({type:"success",message:"已登录"})
		url.value = userstore.user.avatarUrl
	}else{
		Notify({ type: "danger", message: "未登录" })
		show.value = true 
	}

	// 登录状态1 2
	// const res = await RequestUserStatus()
	// console.log("acount>>>",res.data)
	// // 登录状态1 不存在则调用 登录状态2
	// if (res.data.account.status==-10){
	// 	const res = await RequestUserStatus2()
	// 	console.log("status>>>",res.data)
	// 	if(res.data.account.status == 0){
	// 		Notify({type:"success",message:"已登录"})
	// 		// url.value = res.data.profile.avatarUrl
	// 		show.value = false
	// 	}else{
	// 		Notify({type:"danger",message:"请先登录"})
	// 		show.value = true
	// 		// show.value = false  //测试已登录	
	// 	}
	// 	return
	// }
	// if(res.data.account.status == 0){
	// 	Notify({type:"success",message:"已登录"})
	// 	userstore.saveUser(res.data.profile.userId)
	// 	url.value = res.data.profile.avatarUrl
	// 	show.value = false
	// } else {
	// 	Notify({ type: "danger", message: "请先登录" })
	// 	show.value = true
	// 	// show.value = false  //测试已登录

	// }
}
useUserStatus()


</script>

<style lang="scss" scoped>
.van-nav-bar {
	font-weight: bold;
	background-color: #d30707;

	.van-nav-bar__left {
		a {
			color: white;
			font-size: 16px;
		}
	}

	:deep(.van-nav-bar__title) {
		background-color: rgb(247, 247, 247);
		height: 0.7rem;
		line-height: 0.7rem;
		font-size: 0.5rem;
		border-radius: 30px;
		box-sizing: border-box;
		max-width: 50%;
		flex: 1;
		text-align: left;
		padding-left: 30px;
		color: #232326;

		a {
			color: #232326;
			font-size: 16px;
		}
	}

	.van-nav-bar__right {
		a {
			color: white;
			font-size: 16px;
		}
	}

	.van-image {
		margin-left: 5px;
	}
}
.himg{
	width: 40px;
	height: 40px;
}
</style>
